;==============================================================================
; 调试步骤5：保护模式 + 完整显示
;==============================================================================
bits 16
org 0x7c00

start:
    cli
    xor ax, ax
    mov ds, ax
    mov es, ax
    mov ss, ax
    mov sp, 0x7c00
    sti
    
    mov ah, 0x0e
    mov al, '1'
    int 0x10
    
    in al, 0x92
    or al, 2
    out 0x92, al
    mov al, '2'
    int 0x10
    
    lgdt [gdt_descriptor]
    mov al, '3'
    int 0x10
    
    mov eax, cr0
    or eax, 1
    mov cr0, eax
    
    jmp 0x08:pm_mode

align 8
gdt_start:
    dq 0x0000000000000000

gdt_code:
    dw 0xFFFF
    dw 0x0000
    db 0x00
    db 0b10011010
    db 0b11001111
    db 0x00

gdt_data:
    dw 0xFFFF
    dw 0x0000
    db 0x00
    db 0b10010010
    db 0b11001111
    db 0x00

gdt_end:

gdt_descriptor:
    dw gdt_end - gdt_start - 1
    dd gdt_start

bits 32
pm_mode:
    mov ax, 0x10
    mov ds, ax
    mov ss, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov esp, 0x90000
    
    ; 清屏
    mov edi, 0xb8000
    mov ecx, 80 * 25
    mov ax, 0x0f20
    rep stosw
    
    ; 显示成功消息
    mov edi, 0xb8000
    mov esi, msg_success
    mov ah, 0x0a
.loop:
    lodsb
    cmp al, 0
    je .done
    stosw
    jmp .loop
.done:
    jmp $

msg_success: db 'STEP 5: Protected Mode + Display OK!', 0

times 510 - ($ - $$) db 0
dw 0xaa55

